package com.dubbo1.lib.service;

import com.alibaba.fastjson.JSON;
import com.dubbo1.api.api.Dubbo1Service;
import com.dubbo1.api.dto.DubboBaseDto;
import com.dubbo1.api.dto.req.Dubbo1ParamDto;
import com.dubbo1.lib.cloud.Dubbo2Cloud;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 负载均衡--轮询调用
 */
@Slf4j
@Service
public class Dubbo1ServiceImpl implements Dubbo1Service {

    @Autowired
    Dubbo2Cloud dubbo2Cloud;

    /**
     * @param param 消费者服务接口
     */
    @Override
    public DubboBaseDto queryDubbo1Consum(Dubbo1ParamDto param) {
        //调用dubbo2服务接口
        Dubbo1ParamDto var1 = new Dubbo1ParamDto();
        var1.setName(param.getName());
        var1.setId(param.getId());
        //DubboBaseDto result1 = dubbo2Cloud.dubbo2test(var1);
        DubboBaseDto result2 = dubbo2Cloud.dubbo2test(var1);
        //log.info("dubbo2接口返回实体result1:{}", JSON.toJSONString(result1));
        log.info("dubbo2接口返回实体result2:{}", JSON.toJSONString(result2));
        return result2;
    }

    /**
     * @param param 生产者服务接口
     */
    @Override
    public DubboBaseDto queryDubbo1Provide(Dubbo1ParamDto param) {
        log.info("接收到dubbo2请求====参数:{}", JSON.toJSON(param));
        return new DubboBaseDto("200", "", param);
    }
}
